/*
 * Copyright 2009 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.configleon.resource;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;

public class ApplicationPropertyResources extends AbstractPropertyResources {

    private Log logger = LogFactory.getLog(ApplicationPropertyResources.class);

    private String resourcePath;

    public List<Resource> getResources(String configLocation)
        throws FileNotFoundException {

        if (resourcePath == null || resourcePath.length() == 0) {
            String msg = "The resourcePath property needs to be set on ApplicationPropertyResources.";
            logger.error(msg);
            throw new IllegalStateException(msg);
        }

        List<Resource> resources = new ArrayList<Resource>();
        addResource(resources, resourcePath + "/config-global.properties");
        addResource(resources, resourcePath + "/config-" + configLocation + ".properties");

        return resources;
    }

    public void setResourcePath(String resourcePath) {
        this.resourcePath = resourcePath;
    }
}
